<?php
function image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}	
if ( function_exists('register_sidebar') ) {
	
	register_sidebar(array('name'=>__('Left Sidebar','language'),
		'before_widget' => '<div class="hot-news rounds">',
		'after_widget' => '</div>',
		'before_title' => '<h4>',
		'after_title' => '</h4>'
	));
	register_sidebar( array(
		'name' => __( 'Slideshow','language' ),
		'description' => __( 'Home Page Slideshow.','language'),
		'id' => 'slideshow-widget-area',
		'before_widget' => '',
        'after_widget' => '',
        'before_title' => '',
        'after_title' => '',
	) );
	}
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'slideshow',
array(
'labels' => array(
'name' => __( 'Slideshow','language' ),
'add_new' => __( 'Add Photo','language' ),
				'add_new_item' => __( 'Add Photo' ,'language'),
				'edit_item' => __( 'Edit Photo ' ,'language'),
				'new_item' => __( 'Add New Photo ' ,'language'),
				'view_item' => __( 'View Photo' ,'language'),
				'search_items' => __( 'Search Photo' ,'language'),
				'not_found' => __( 'No Photo Found' ,'language' ),
				'not_found_in_trash' => __( 'No Photos Found In Trash' ,'language'),
'query_var' => true,
'rewrite' => false,
'singular_name' => __( 'Photo','language' )
),
'menu_position' => '5',
'public' => true,
'menu_icon' => get_bloginfo('template_url') . '/images/mc/slideback.png', 
'supports' => array("title",'editor'),
			'capability_type' => 'post',) ); }

add_action( 'after_setup_theme', 'yourtheme_setup' );
if ( ! function_exists('yourtheme_setup') ):
/**
* @uses add_custom_image_header() To add support for a custom header.
* @uses register_default_headers() To register the default custom header images/pink provided with the theme.
*
* @since 3.0.0
*/
function yourtheme_setup() {

// This theme uses post thumbnails
	add_theme_support( 'post-thumbnails' );
	set_post_thumbnail_size( 413, 230 );	
	// Add default posts and comments RSS feed links to head
	add_theme_support( 'automatic-feed-links' );
	$lang = TEMPLATE_PATH . '/languages';
	load_theme_textdomain('language', $lang);	
	// custom background support		
/** Tell WordPress to run yourtheme_setup() when the 'after_setup_theme' hook is run. */
// Menu Registration

if ( function_exists( 'register_nav_menus' ) ) {
	register_nav_menus(
	array(
		'social' => 'Header Social',
		'sidebar-nav' => 'Sidebar Navigation'
	));
}
// Your changeable header business starts here
define( 'HEADER_TEXTCOLOR', '' );
// No CSS, just IMG call. The %s is a placeholder for the theme template directory URI.
define( 'HEADER_IMAGE', '%s/images/mc/logo.png' );
// The height and width of your custom header. You can hook into the theme's own filters to change these values.
// Add a filter to yourtheme_header_image_width and yourtheme_header_image_height to change these values.
define( 'HEADER_IMAGE_WIDTH', apply_filters( 'yourtheme_header_image_width', 523 ) );
define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'yourtheme_header_image_height',	119 ) );
// We'll be using post thumbnails for custom header images/pink on posts and pages.
// We want them to be 940 pixels wide by 198 pixels tall (larger images/pink will be auto-cropped to fit).
//set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
// Don't support text inside the header image.
define( 'NO_HEADER_TEXT', true );
// Add a way for the custom header to be styled in the admin panel that controls
// custom headers. See yourtheme_admin_header_style(), below.
add_custom_image_header( '', 'yourtheme_admin_header_style' );
}
endif;
if ( ! function_exists( 'yourtheme_admin_header_style' ) ) :
/**
* Styles the header image displayed on the Appearance > Header admin panel.
*
* Referenced via add_custom_image_header() in yourtheme_setup().
*
* @since 3.0.0
*/
function yourtheme_admin_header_style() {
?>
<style type="text/css">
#headimg {
height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
width: <?php echo HEADER_IMAGE_WIDTH; ?>px;
}
#headimg h1, #headimg #desc {
display: none;
}
</style>
<?php
}
endif;

// pagination method	
	function theme_pagination($pages = ''){
		global $paged;
		
		if(empty($paged))$paged = 1;
		
		$prev = $paged - 1;							
		$next = $paged + 1;	
		$range = 3; // only change it to show more links
		$showitems = ($range * 2)+1;
		
		if($pages == '')
		{	
			global $wp_query;
			$pages = $wp_query->max_num_pages;
			if(!$pages)
			{
				$pages = 1;
			}
		}
				
		if(1 != $pages){
			echo "<div id='pagination'>";
			echo ($paged > 2 && $paged > $range+1 && $showitems < $pages)? "<a href='".get_pagenum_link(1)."' class='btn'>&laquo;</a> ":"";
			echo ($paged > 1 && $showitems < $pages)? "<a href='".get_pagenum_link($prev)."' class='btn'>&laquo;</a> ":"";
			
				
			for ($i=1; $i <= $pages; $i++){
				if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){
					echo ($paged == $i)? "<a href='".get_pagenum_link($i)."' class='btn current'>".$i."</a> ":"<a href='".get_pagenum_link($i)."' class='btn'>".$i."</a> "; 
				}
			}
			
			echo ($paged < $pages && $showitems < $pages) ? "<a href='".get_pagenum_link($next)."' class='btn'>&raquo;</a> " :"";
			echo ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) ? "<a href='".get_pagenum_link($pages)."' class='btn'>&raquo;</a> ":"";
			echo "</div>";
			}
	}
	function my_render_ie_pie() {
echo '
<!--[if lte IE 8]>
<style type="text/css" media="screen">
.rounds,
.rounds5,
#header .header-nav li,
#sidebar .hot-news h4,
.left-col #respond input, 
.left-col #respond textarea,
.left-col #pagination a,
.left-col .slider .slide img,
.left-col .post .post-data img
 {
behavior: url('.trailingslashit(get_bloginfo('template_url')).'js/PIE.php);
}
</style>
<![endif]-->
';
}
add_action('wp_head', 'my_render_ie_pie', 8);
class SD_Widget extends WP_Widget {
	function SD_Widget() {
		$widget_ops = array( 'description' => (__('Add a Slideshow to the Home Page','language')));
		$this->WP_Widget('slideshow_home_widget', 'Home Page Slideshow', $widget_ops);
	}
	function widget($args, $instance) {
		global $slideid;
		extract($args, EXTR_SKIP);
		include(TEMPLATEPATH . '/slideshow.php');
	}
	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		return $instance;
	}
}
register_widget('SD_Widget');
?>